package com.example.mybatisfinaltask.controller;

import com.example.mybatisfinaltask.pojo.Dept;
import com.example.mybatisfinaltask.pojo.Result;
import com.example.mybatisfinaltask.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;
    @GetMapping("/depts")
    Result list(){
        log.info("查询全部数据");
        return Result.success(deptService.selectAll());
    }
    @DeleteMapping("/depts/{id}")
    Result delete(@PathVariable Integer id){
        deptService.deleteById(id);
        log.info("根据id删除：{}",id);
        return Result.success();
    }
    @PostMapping("/depts")
    Result add(@RequestBody Dept dept){
        deptService.add(dept);
        return Result.success();
    }
    @GetMapping("/depts/{id}")
    Result getById(@PathVariable Integer id){
        log.info("根据id查询：{}",id);
        return Result.success(deptService.getById(id));
    }
    @PutMapping("/depts")
    Result modify(@RequestBody Dept dept){
        log.info("根据id修改:{}",dept.getId());
        deptService.modify(dept);
        return Result.success();
    }
}
